package controller

import (
	"hft/Database/admin"
	services "hft/Http/Services"
	utils "hft/Http/Utils"
	"hft/tools"

	"github.com/gin-gonic/gin"
)

type FeedBack struct{}

func (*FeedBack) GetAccountFeedBackList(c *gin.Context) {

	var paginate utils.Page

	c.ShouldBind(&paginate)

	claims, err := tools.GetClaims(c)

	if err != nil {
		utils.FailWithMessage("授权失败", c)
		return
	}

	list, err := services.FeedBackService.GetAccountFeedBack(&paginate, claims.BaseClaims)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.OkWithData(list, c)

}

func (*FeedBack) CreateFeedAccountBack(c *gin.Context) {

	var data *admin.FeedBack

	c.ShouldBindJSON(&data)

	claims, err := tools.GetClaims(c)

	if err != nil {
		utils.FailWithMessage("授权失败", c)
		return
	}

	err = services.FeedBackService.CreateFeedAccountBack(data, claims.BaseClaims)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
	}

	utils.Ok(c)

}

func (*FeedBack) GetAllFeedBack(c *gin.Context) {

	var paginate utils.Page

	c.ShouldBind(&paginate)

	list, err := services.FeedBackService.GetAllFeedBack(&paginate)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.OkWithData(list, c)

}

func (*FeedBack) OperaFeedback(c *gin.Context) {

	var data *admin.FeedBack

	c.ShouldBindJSON(&data)

	err := services.FeedBackService.OperaFeedback(int(data.ID), data.Status)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.Ok(c)

}

var FeedBackController = new(FeedBack)
